<%@page contentType="text/html; charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-layout.tld" prefix="layout" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>


<!DOCTYPE html>
<HTML>
<HEAD>
	<TITLE>组织树</TITLE>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta http-equiv="x-ua-compatible" content="ie=8" />
	<link rel="stylesheet" href="<%=request.getContextPath() %>/css/ztree/demo.css" type="text/css">
	<link rel="stylesheet" href="<%=request.getContextPath() %>/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery.ztree.core-3.5.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery.ztree.excheck-3.5.js"></script>

	<!--
	<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery.ztree.exedit-3.5.js"></script>
	-->
<SCRIPT type="text/javascript">
		var defaultSelectedNodes = parent.document.form1.old_code_id.value;
		var  nameArray=new Array(0);
		var codeArray=new Array(0);
		codeArray=defaultSelectedNodes.split(",");//初始化将系统之前选中的值赋给codeArray
		var setting = {
			   check: {
			    enable: true
		        },
		        data: {
					simpleData: {
						enable: true
					}
				}
		}
		var zNodes =[
	     		<c:forEach var="bean" items="${lcvo}" varStatus="status">
	     			<c:if test="${fn:length(bean.total_code) > 3}">
	     			 
	     		    	{id:${bean.total_code}, pId:${fn:substring(bean.total_code,0,fn:length(bean.total_code)-3)} , name:"${bean.name}",checkId:"${bean.id}",checked:isTrue(${bean.total_code})}
	     		    </c:if>
	     		   <c:if test="${fn:length(bean.total_code) == 3}">
	     			 
	     		   	 {id:${bean.total_code}, pId:0, name:"${bean.name}",checkId:"${bean.id}" ,checked:isTrue(${bean.total_code})}
	     		    </c:if>
	     		   <c:if test="${status.last==false}">, </c:if>
	     		</c:forEach>			
		     ];
		
		$(document).ready(function(){
			var t = $("#treeDemo");
			t = $.fn.zTree.init(t, setting, zNodes);	
		});
		function isTrue(total_code){
			var istrue = false;
			for(var i =0;i<codeArray.length;i++){
				if(codeArray[i] == total_code){
					istrue = true;
				}
			}
			return istrue;
		}
		function returnValueName(){
			var submitObjectArray = new Array(0);
			var t = $.fn.zTree.getZTreeObj("treeDemo");
			nodes=t.getCheckedNodes(true);
		    if(nodes.length>0){
                 for(var nlen=0;nlen<nodes.length;nlen++){
                	var tempObj = new Object();
     				tempObj["childName"] = nodes[nlen].name;
     				tempObj["returnValue"] = nodes[nlen].id;
     				submitObjectArray[submitObjectArray.length] = tempObj
                  }
			    }
		    return submitObjectArray;
		}
		
	</SCRIPT>
</HEAD>

<BODY>
<div class="content_wrap" style="margin:0 auto; margin-top:30px;float: none;">
	<div class="zTreeDemoBackground left" style="margin:0 auto ;margin-top:30px; margin-left:15px; float: left;">
		<ul id="treeDemo" class="ztree" style="display:inline-block;*display:inline;margin:0 auto;width: 260px;" ></ul>
<!--		<input type="button" value="确认" onclick="javascript:qd();"/><input type="button" value="取消" onclick="window.close()" />-->
	</div>
</div>

     

</BODY>
</HTML>